<?php

/**
 * Created by PhpStorm.
 * User: yf
 * Date: 2018/3/6
 * Time: 下午12:14
 */
namespace App\Server\Process;

use App\Server\SwooleServer;
use App\Utility\Common;
use EasySwoole\Core\Swoole\Process\AbstractProcess;
use Swoole\Process;
use App\Msg\MsgCode;
use App\Model\Message\MessageBean;
use App\Msg\MsgInfo;

class OnlineNum extends AbstractProcess
{

    public function run(Process $process)
    {
        $common = new Common();
        $common->E("OnlineNum Process run");
        
        $swooleserver = new SwooleServer();
        // TODO: Implement run() method.
        $this->addTick(10000, function () use ($common, $swooleserver) {
            $num = $common->onLineNum();
            $num = intval($num);
            $message = new MessageBean();
            $message->setAddtime(time());
            $message->setContent($num);
            $message->setType(MessageBean::OUTLINE_NUM_TYPE);
            $msg = $common->dealMessage(MsgCode::ONLINE_NUM_MSG, $message, MsgInfo::ONLINE_NUM_TITLE);
            $common->broadcast($msg);
        });
    }

    public function onShutDown()
    {
        // TODO: Implement onShutDown() method.
    }

    public function onReceive(string $str, ...$args)
    {
        // TODO: Implement onReceive() method.
        var_dump('process rec' . $str);
    }
}